<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增仓库入库记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-manager-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品：</label>
                <div class="col-sm-8">
                    <select id="drugId" name="drugId" class="form-control select2-multiple" required>
                        <option value=""></option>
                        <option th:each="item:${drugList}" th:value="${item.id}" th:text="${item.drugName}+'（'+${item.drugAlias}+'）'"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品名称：</label>
                <div class="col-sm-8">
                    <input id = "drugName" name="drugName" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">药品别名：</label>
                <div class="col-sm-8">
                    <input id = "drugAlisa" name="drugAlisa" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">过期时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="expirationTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">入库数量：</label>
                <div class="col-sm-8">
                    <input name="insertNum" class="form-control" type="number" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/warehouse/manager"
        $("#form-manager-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-manager-add').serialize());
            }
        }

        $("input[name='expirationTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $('#drugId').on('select2:select', function (e) {
            var content = e.params.data.text;
            var start = content.indexOf("（");
            var end = content.lastIndexOf("）");
            $('#drugName').val(content.substring(0, start));
            $('#drugAlisa').val(content.substring(start + 1, end));
        });
    </script>
</body>
</html>